﻿<% 
       Function online()
		dim rs,sql,i

		Set Rs = Server.CreateObject("Adodb.Recordset")



		Sql = "select [id],[nid],[time],[dltime],[weizhi] from qingtian_online where DATEDIFF('s', [time], now()) > 60*"&qingtian.confff("zti")&" order by [time] asc"
		Rs.Open Sql,conn,1,3
		if not (rs.bof and rs.eof)  then
		For i=1 to rs.RecordCount
			if rs("nid")>0 then
                        if qingtian.vip(rs("nid"))="VIP会员" then
			conn.execute("update qingtian_user set [weizhi]='"&rs("weizhi")&"',[dltime]='"&rs("time")&"',online=0,zf=zf + " & clng(DATEDIFF("h", rs("dltime"), rs("time"))) * 20 &",gradezf=gradezf + " & clng(DATEDIFF("h", rs("dltime"), rs("time"))) * 20 &" where id="&rs("nid")&"")
                        else
			conn.execute("update qingtian_user set [weizhi]='"&rs("weizhi")&"',[dltime]='"&rs("time")&"',online=0,zf=zf + " & clng(DATEDIFF("h", rs("dltime"), rs("time"))) * 10 &",gradezf=gradezf + " & clng(DATEDIFF("h", rs("dltime"), rs("time"))) * 10 &" where id="&rs("nid")&"")
                        end if
			end if
		rs.delete
		Rs.MoveNext
		next
		end if
		Rs.close

		if sid="Null" or qingtian.vipttt(qingtian.nid)=1 then

			Sql= "select [id],[nid],[name],[time],[ip],[weizhi],[sessionid] from qingtian_online where ip='"&Request.ServerVariables("REMOTE_ADDR")&"'"
			Rs.Open Sql,conn,1,3
			if rs.bof and rs.eof then
			rs.addnew
			end if
			rs("nid")=0
			rs("name")=qingtian.confff("hui")&"("&Request.ServerVariables("REMOTE_ADDR")&")"

		else
			Sql= "select [id],[nid],[name],[time],[ip],[weizhi],[sessionid] from qingtian_online where [nid]=(select id from qingtian_user where [sid]= '"&qingtian.Formatsid(sid)&"')"
			Rs.Open Sql,conn,1,3
			if rs.bof and rs.eof then
			conn.execute("update qingtian_user set [online]=1,[onlinetime]=now() where [sid]= '"&qingtian.Formatsid(sid)&"'")
			conn.execute("update qingtian_user set [zf]=[zf] + 30,[gradezf]=[gradezf] + 30 where DATEDIFF('d', [dltime], now())>0 and [sid]= '"&qingtian.Formatsid(sid)&"'")
			rs.addnew
			end if

			rs("nid")=qingtian.nid
			rs("name")=session("username")


		end if
			rs("time")=now
			rs("weizhi")="http://" & request.ServerVariables("Server_NAME") & request.ServerVariables("SCRIPT_NAME") 
			rs("ip")=Request.ServerVariables("REMOTE_ADDR")
			rs.update

		Rs.close
		set rs=nothing

    End Function

%>